#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include "../Util/log.hpp"

using namespace std;

const string file = "./commentfile";

bool send_comment(string& str)
{
    auto it = str.find("垃圾");
    if(it != string::npos)
    {
        LOG(INFO) << "含有敏感信息" << "\n";
        return false;
    }
    ofstream out(file, std::ios::app);
    if(!out.is_open())
    {
        LOG(ERROR) << "打开文件失败" << "\n";
        return false;
    }
    str += "\n";
    out.write(str.c_str(), str.size());
    out.close();
    return true;
}

bool recv_comment(string& str)
{
    str.clear();
    std::ifstream in(file);
    if(!in.is_open())
    {
        LOG(ERROR) << "打开文件失败" << "\n";
        return false;
    }
    std::string line;
    while(getline(in, line))
    {
        str += line;
        str += "\n";
    }
    in.close();
    return true;
}